package com.example.K501;

import java.util.*;

import android.database.sqlite.SQLiteOpenHelper;


public class AccountDatabase
{
	private HashMap<String, String> database;
	private ArrayList<Account> accounts;
	public AccountDatabase()
	{
		database = new HashMap<String, String>();
		accounts = new ArrayList<Account>();
		//TODO Delete temp admin account
		
		newAccount("WaltonWellness", "WaltonWellness", "Ritter");
	}
	
	public boolean newAccount(String name, String username, String password)
	{
		//does not already contain username
		//username does not equal password 
		//one capital letter in password
		boolean valid = !database.containsKey(username) 
		&& !username.equals(password)
		&& !password.toLowerCase().equals(password);
		if(valid)
		{
			database.put(username, password);
			Account newAcc = new Account(name, username, password);
			accounts.add(newAcc);
			return true;
		}
		return false;
	}
	
	public boolean verify(String username, String password)
	{
		return database.containsKey(username) && database.get(username).equals(password);
	}
	
	public void changePassword(String username, String newPass)
	{
		database.remove(username);
		database.put(username, newPass);
	}
	
	public Account getAccount(String username)
	{
		if(!database.containsKey(username))
			return null;
		int i = 0;
		while (i < accounts.size() && !accounts.get(i).getUsername().equals(username))
		{
			i++;
		}
	    return accounts.get(i);
	}

}
